<?php

include_once(dirname(__FILE__).'/../../classes/AdminTab.php');

class AdminAccueil extends AdminTab
{
public function __construct()
	{
	 	global $cookie;

	 	$this->table = 'accueil';
	 	$this->className = 'Accueil';
	 	$this->lang = false;
	 	$this->edit = true;
	 	$this->delete = true;
	 	
	 	$this->fieldImageSettings = array('name' => 'img', 'dir' => 's');
	 	
	 	$this->fieldsDisplay = array(
		'id_accueil' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
		'titre' => array('title' => $this->l('Titre'), 'width' => 150),
		'texte' => array('title' => $this->l('Texte'), 'width' => 300),
	 	'img'   => array('title' => $this->l('Image'), 'align' => 'center', 'image' => 't', 'orderby' => false, 'search' => false),
	 	'lien'  => array('title' => $this->l('Lien'), 'width' => 300)
		);
		
		parent::__construct();
	}
	
public function displayForm($isMainTab = true)
	{
		global $currentIndex;
		parent::displayForm();
		
		if (!($obj = $this->loadObject(true)))
			return;
		echo '
		<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" enctype="multipart/form-data">
		'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
			<fieldset>
				<label>Titre</label>
				<div class="margin-form">
					<input type="text" size="100" name="titre" value="'.htmlentities(Tools::getValue('titre', $obj->titre), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
				</div>
	      <label>Texte</label>
				<div class="margin-form">
					<textarea rows="10" cols="97" name="texte">'.htmlentities(Tools::getValue('texte', $obj->texte), ENT_COMPAT, 'UTF-8').'</textarea> <sup>*</sup>
				</div>
				<label>Image</label>
				<div class="margin-form">
					<input type="file" name="image" />
				</div>
				<label>Lien</label>
				<div class="margin-form">
					<input type="text" size="100" name="lien" value="'.htmlentities(Tools::getValue('lien', $obj->lien), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
				</div>
				<div class="margin-form">
					<input type="submit" value="'.$this->l('   Save   ').'" name="submitAdd'.$this->table.'" class="button" />
				</div>
				<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
			</fieldset>
		</form>';
	}	
 public function afterImageUpload()
	{
		if (!($obj = $this->loadObject(true)))
			return;
		@rename(_PS_IMG_DIR_.'t/'.$obj->id.'.jpg', _PS_IMG_DIR_.'t/'.$obj->class_name.'.jpg');
	}
}
?>